// 开展培训
function TrainRecords() {
    var _this = this;
    var page;
    _this.page_size = 10;

    // init
    _this.init = function(_page) {
        page = _page;
        _this.initTable();
        _this.initEvent();
    };

    _this.initTable = function() {
        var list_url = appPath + "/statistics/project_statistics_list";
        page.init("select_trainRecords_form", list_url, "select_trainRecords_list", "select_trainRecords_page", 1, _this.page_size);
        page.goPage(1);
        page.list = function(dataList){
            _this.obj = dataList;
            if(dataList == null){
                return;
            }
            var len = dataList.length;
            var inner = "", item;
            var process = "未完成";
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                // 组装数据
                inner += "<tr>";
                inner += '<td width="50">'+(parseInt(i)+1)+'</td>';
                inner += '<td width="100">'+ item['user_name'] + '</td>';   //姓名
                inner += '<td width="100">'+ item['company_name'] + '</td>';   //单位
                inner += '<td width="100">'+ item['dept_name'] + '</td>';   //部门
                inner += '<td width="100">'+ TimeUtil.getHouAndMinAndSec(item['requirement_studytime']*60) + '</td>';   //应修学时
                inner += '<td width="100">'+ TimeUtil.getHouAndMinAndSec(item['total_studytime']) + '</td>';    //已修学时
                process = parseInt(item['train_process'].replace("%", "")) >= 100 ? '已完成' : '未完成'; //进度
                inner += '<td width="100">'+ process + '</td>';
                inner += "</tr>";
            }
            return inner;
        }

    };



    _this.initEvent = function () {
        //搜索
        $("#user_search").click(function () {
            _this.initTable();
        });

        //全部
        $("#user_all").click(function () {
            $("#trainUserName").val("");
            $("#trainStatus").val("");
            $("#deptName").val("");
            _this.initTable();
        });


    };



    // 确定出勤
    _this.sureAttend=function (status) {
        var userIds = _this.getUserIds();
        if(userIds.length > 0){
            // 出勤
            $.ajax({
                url : appPath + '/admin/projectCenterTrain/updateAttendStatus',
                dataType : 'json',
                async : false,
                type : 'post',
                data : {
                    "projectId" : $("#projectId").val(),
                    "userIds" : userIds.join(","),
                    "status" : status
                },
                success : function (data) {
                    var result = data.code;
                    if (10000 == result) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        layer.msg('操作成功',{time:1000});
                        _this.initTable();  //刷新列表
                    } else {
                        layer.alert('操作失敗');
                    }
                }
            });
        }else{
            layer.msg("未选择人员");return;
        }
    };

    _this.getUserIds = function () {
        var userIdAll = [];
        $("#select_trainRecords_list :checkbox:checked").each(function () {
            userIdAll.push($(this).attr("data-id"));
        });
        return userIdAll;
    }

}

var trainRecords = new TrainRecords();